package com.das.metrocloud.ssoserver.config;

import com.das.framework.common.extvo.LoginInfo;
import com.das.framework.common.jwt.JWTHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


@Component
public class JwtTokenSevice {


    /**
    *  过期时间
    **/
    @Value("${dascloud.authrization.token.expire}")
    private int expire;




    @Autowired
    private AuthKeyConfig keyConfig;



    /**
    *   生成Token:  LoginInfo + userPriKey + expire
     *
     *              用户信息   +  用户私钥  + 过期时间
     *
     *  到时解析时候:
     *
    */
    public String generateToken(final LoginInfo loginUser) throws Exception {


        return JWTHelper.generateToken(loginUser, this.keyConfig.getUserPriKey(), this.expire);


    }



    /**
     *
     *
     *
     */
    public LoginInfo getInfoFromToken(final String token) throws Exception {
        return JWTHelper.getInfoFromToken(token, this.keyConfig.getUserPubKey());
    }
}
